<?php
defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();

if($_RQ['op']=='list'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid']
	);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.$_RQ['nickname'].'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['account'])){
		$params['account like']='%'.$_RQ['account'].'%';
		$return['params']['account']=$_RQ['account'];
	}
	if(isset($_RQ['idcard_check'])){
		$params['idcard_check']=$_RQ['idcard_check'];
		$return['params']['idcard_check']=$_RQ['idcard_check'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','idcard_check');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			if(!isset($item['idcard_check'])){
				$item['idcard_check']=0;
			}
			$member = get_member($item['mid']);
			$item=array_merge($item,$member);
			$item['avatar']=$member['avatar']?$member['avatar']:'../addons/jy_jdpm/resource/images/userlogo.jpg';
			$item['createtime']=date('Y/m/d H:i:s',$member['createtime']);
			$item['email']=$member['email']?$member['email']:'无';	
			$item['pcd']=json_decode($member['pcd'],true);
			if($item['pcd']){
				$item['pcd']=$item['pcd']['province'].$item['pcd']['city'].$item['pcd']['district'];
			}
			$item['nickname']=$member['nickname']?$member['nickname']:'云拍校尉';
			$item['sex'] = $member['sex'] ? '(男)' : '(女)';
			$item['username']=$member['username']?$member['username']:'无';
			$item['mobile']=$member['mobile']?$member['mobile']:'无';				
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
			array('op'=>'edit','title'=>'添加用户'),
		),
		'export'=>'export',
		'export_title'=>'用户数据',
		'list'=>array('key'=>'mid','data'=>'list','delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('type'=>'img_string','title'=>'登录账号','img'=>'avatar',
			'data'=>array(
				array('title'=>'账号：','name'=>'username'),
				array('title'=>'昵称：','name'=>'nickname','unit'=>'sex')
				)
			),
			array('title'=>'邮箱/手机号','type'=>'img_string',
			'data'=>array(
				array('title'=>'邮箱：','name'=>'email'),
				array('title'=>'手机号码：','name'=>'mobile')
				)
			),
			array('title'=>'地区/地址','type'=>'img_string',
			'data'=>array(
				array('title'=>'地区：','name'=>'pcd'),
				array('title'=>'地址：','name'=>'address')
				)
			),
			array('title'=>'登录ip/注册时间','type'=>'img_string',
			'data'=>array(
				array('title'=>'登陆IP：','name'=>'reg_ip'),
				array('title'=>'注册于：','name'=>'createtime')
				)
			),
			array('name'=>'idcard_check','title'=>'身份认证状态','type'=>'radio','options'=>'idcard_check'),
			
		
		),'action'=>array(
			array('type'=>'href','op'=>'address','title'=>'地址维护'),
			array('op'=>'sendsms','title'=>'发送站内信','type'=>'modal','plugin'=>'jy_jdpm'),
			array('type'=>'href','op'=>'down','title'=>'他的推广'),
			
		),),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'会员UID','name'=>'mid','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'手机号','name'=>'mobile','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'用户账号','name'=>'account','help'=>''),
			array('type'=>'string','width'=>'15','title'=>'昵称','name'=>'nickname','help'=>''),
			array('type'=>'select','width'=>'15','title'=>'身份认证状态','name'=>'idcard_check','options'=>'idcard_check2','select_title'=>'请选择认证状态'),
		),
	);
	$return['idcard_check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['idcard_check2']=array(
		array('id'=>0,'title'=>'未申请认证'),
		array('id'=>1,'title'=>'待认证'),
		array('id'=>2,'title'=>'已认证'),
		array('id'=>3,'title'=>'未通过'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='address'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('core_address',array('mid'=>$_RQ['mid'],'uniacid'=>$_SESSION['uniacid']),array($pindex,$psize),$total);
	if($list){
		foreach($list as &$item){
			if(!$item['provaddress']){
				$item['pcd']=json_decode($item['pcd'],true);
				$item['provaddress']=$item['pcd']['province'].$item['pcd']['city'].$item['pcd']['district'];
			}
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			//array('op'=>'address','title'=>'地址管理'),
			//array('op'=>'addressedit','title'=>'添加地址'),
			array('op'=>'list','title'=>'返回会员列表'),
		),
		
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('name'=>'name','title'=>'姓名','type'=>'string'),
			//array('name'=>'email','title'=>'邮箱','type'=>'string'),
			array('name'=>'mobile','title'=>'手机号','type'=>'string'),
			array('name'=>'provaddress','title'=>'地区','type'=>'string'),
			array('name'=>'address','title'=>'地址','type'=>'string'),
			array('name'=>'isdefault','title'=>'是否默认','type'=>'radio','options'=>'default'),
			
		
		),'action'=>array(
			array('type'=>'href','op'=>'addressedit','title'=>'编辑'),
			
		),),
	
	);
	$return['default']=array('0'=>'否','1'=>'是');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='addressedit'){
	$id=intval($_RQ['mid']);
	if($id){
		$item=pdo_get('core_address',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['pcd']=json_decode($item['pcd'],true);
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'adpost',
		'desc'=>'地址信息',
		'tabs'=>array(
			//array('op'=>'address','title'=>'地址管理'),
			//array('op'=>'addressedit','title'=>'添加地址'),
			array('op'=>'list','title'=>'返回会员列表'),
		),
		'edit'=>array(
			array('name'=>'name','title'=>'收货人','type'=>'string'),
			array('name'=>'mobile','title'=>'电话','type'=>'string'),
			array('type'=>'pcd','name'=>'pcd','title'=>'所在地','options'=>'pcd'),
			array('type'=>'string','name'=>'address','title'=>'街道地址','help'=>'不需要写省市区, 必须大于五个字符'),	
			array('name'=>'isdefault','title'=>'是否默认','type'=>'radio','options'=>'default'),
			
		)
	);
	$return['default']=array('0'=>'否','1'=>'是');
	$return['htmls']=$htmls;
	$return['pcd']=cfc('tools')->pcd();
	exi($return);
}
if($_RQ['op']=='adpost'){
	$post=get_postdata();
	$id=$post['mid'];
	$uid=pdo_getcolumn('core_address',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']),'mid');
	$post['pcd']=ijson_encode($post['pcd']);
	if($post['isdefault']==1){
		pdo_update('core_address',array('isdefault'=>0),array('mid'=>$uid));
	}
	
	pdo_update('core_address',$post,array('mid'=>$post['mid']));
	exi('编辑成功','','list');
	
	
}
if($_RQ['op']=='export'){
	$params=array(
		'uniacid'=>$_SESSION['uniacid']
	);
	if($_RQ['mid']){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	
	if(!empty($_RQ['nickname'])){
		$params['nickname like']='%'.$_RQ['nickname'].'%';
		$return['params']['nickname']=$_RQ['nickname'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	if(!empty($_RQ['account'])){
		$params['account like']='%'.$_RQ['account'].'%';
		$return['params']['account']=$_RQ['account'];
	}
	if(isset($_RQ['idcard_check'])){
		$params['idcard_check']=$_RQ['idcard_check'];
		$return['params']['idcard_check']=$_RQ['idcard_check'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','idcard_check');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		$idcard_check=array(
			'0'=>'未申请认证',
			'1'=>'待认证',
			'2'=>'已认证',
			'3'=>'未通过'
		);
		foreach($list as &$item){
			$member = get_member($item['mid']);
			$item=array_merge($item,$member);
			if(!isset($item['idcard_check'])){
				$item['idcard_check']=0;
			}
			$item['able']=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			$item['createtime']=date('Y/m/d H:i:s',$item['createtime']);
			$item['idcard_check']=$idcard_check[$item['idcard_check']];
		}
	}
	$header=array(
		'mid'=>'mid',
		'account'=>'用户账号',
		'nickname'=>'昵称',
		'email'=>'邮箱',
		'mobile'=>'手机号',
		'address'=>'地址',
		'wallet_pledge'=>'总余额',
		'wallet_pledge_freeze'=>'冻结余额',
		'able'=>'可用余额',
		'reg_ip'=>'登录ip',
		'createtime'=>'注册时间',
		'idcard_check'=>'身份认证状态',
	);
	cfc('tools')->export2excel($header,$list,'用户数据-'.date('Y-m-d'));
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['mid']);
	if($id){
		$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		$item['pcd']=json_decode($item['pcd'],true);
	
	}else{
		$item=array();
	}

	$return['item']=$item;
	$return['verify']=array('0'=>'未认证','1'=>'已认证');
	$return['check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['sex']=array('0'=>'女','1'=>'男');
	$return['status']=array('0'=>'禁用','1'=>'启用');
	$return['pcd']=cfc('tools')->pcd();
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回会员列表'),
			
		),
		'desc'=>'会员信息设置',
		'edit_tab'=>true,
		'edits'=>array(
			array(
				'title'=>'基本信息',
				'list'=>array(
					array('type'=>'copy','name'=>'username','title'=>'登录账号','help'=>'不可编辑'),
					array('type'=>'string','name'=>'scorebuy','title'=>'买家得分','help'=>'重置满多少可用, 空或0 不限制'),	
					array('type'=>'radio','name'=>'status','title'=>'状态','options'=>'status'),						
		)
	),
			array(
				'title'=>'实名认证',
				'list'=>array(
					
					array('type'=>'string','name'=>'truename','title'=>'真实姓名'),
					array('type'=>'string','name'=>'idcard','title'=>'身份证号'),
					array('type'=>'image','name'=>'idcard_front','title'=>'身份证正面照片'),
					array('type'=>'image','name'=>'idcard_behind','title'=>'身份证反面照片'),
					array('type'=>'radio','name'=>'idcard_check','options'=>'check','title'=>'实名认证'),					
				)
			),
			array(
				'title'=>'卖家信息',
				'list'=>array(
					array('type'=>'string','name'=>'score','title'=>'卖家得分'),
					array('type'=>'string','name'=>'title','title'=>'店铺名称'),
					array('type'=>'string','name'=>'desc','title'=>'店铺简介'),
					array('type'=>'image','name'=>'logo','title'=>'店铺logo','help'=>'图片尺寸：正方形图片'),
								
				)
			)
	)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='down'){
	$params=array('fromuser'=>intval($_RQ['mid']),'uniacid'=>$_SESSION['uniacid']);
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	//$fields=array('mid','email','avatar','account','nickname','sourceuid');
	$list=pdo_getslice('core_members',$params,array($pindex,$psize),$total,$fields,'','id desc');
	
	if($list){
		foreach($list as &$item){
			$member = get_member($item['mid']);
			$item=array_merge($item,$member);
			if($item['fromuser']){
				$item['fromuser']=pdo_getcolumn('core_members',array('id'=>$item['fromuser']),'nickname');	
			}else{
				$item['fromuser']='总店';
			}
			$item['nickname']=$item['nickname']?$item['nickname']:'云拍校尉';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回会员列表'),
			array('op'=>'down','title'=>'他的推广'),
			
		),
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('name'=>'avatar','title'=>'头像','type'=>'image'),
			array('name'=>'account','title'=>'用户账号','type'=>'string'),
			array('name'=>'nickname','title'=>'昵称','type'=>'string'),
			array('name'=>'fromuser','title'=>'上级','type'=>'string'),
			
		
		),
		
		),
	);
	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$post=get_postdata();
	$id=intval($post['mid']);
	$data=array_fields(array('postalcode','scorebuy','status','truename','idcard','idcard_front','idcard_behind','idcard_check','score','title','desc','logo'),$post);
	if($id){
		pdo_update('jy_jdpm_member',$data,array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
		exi('修改成功','','list');
	}else{
		$insert=array('username'=>trim($post['username']),'salt'=>random(8));
		$insert['password']=get_password($post['password'],$insert['salt']);
		$insert['createtime']=TIMESTAMP;
		$insert['from_os']=get_os();
		$insert['uniacid']=$_SESSION['uniacid'];
		pdo_insert('core_members',$insert);
		$uid=pdo_insertid();
		$data['mid']=$uid;
		$data['createtime']=time();
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('jy_jdpm_member',$data);
		exi('添加成功','','list');
	}
	
}
if($_RQ['op']=='sendsms'){
	$id=intval($_RQ['mid']);
	$item['id']=$id;
	$htmls=array(
		'type'=>'edit',
		'post'=>'set',
		'desc'=>'站内信',
		'edit'=>array(
			'0'=>array('type'=>'text','title'=>'消息内容','name'=>'sms'),
			
		)
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($post['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	
	$data=array('content'=>$post['sms'],'type'=>'系统提示','createtime'=>time(),'mid'=>$id,'uniacid'=>$_SESSION['uniacid']);
	pdo_insert('jy_jdpm_mysms',$data);
	exi('发送成功','',manage_url('jy_jdpm/member/',true));
}
if($_RQ['op']=='credit'){
	$id=intval($_RQ['mid']);
	$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
	$aliv=$aliv?sprintf("%.2f", $aliv):0.00;
	$item['credit']='当前：'.$item['wallet_pledge'].'     冻结：'.$item['wallet_pledge_freeze'].'     可用：'.$aliv;
	$alivlim=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
	$alivlim=$alivlim?sprintf("%.2f", $alivlim):0.00;
	$item['xy']='当前：'.$item['wallet_limsum'].'     冻结：'.$item['wallet_limsum_freeze'].'     可用：'.$alivlim;
	
	$htmls=array(
		'type'=>'edit',
		'post'=>'account',
		'desc'=>'账户信息编辑',
		'edit'=>array(
			array('type'=>'string','title'=>'用户账号','read'=>true,'name'=>'account'),
			array('type'=>'string','title'=>'账户余额','read'=>true,'name'=>'credit'),
			array('type'=>'string','title'=>'信誉额度','read'=>true,'name'=>'xy'),
			array('type'=>'radio','title'=>'操作项','name'=>'do','options'=>'do'),
			array('type'=>'radio','title'=>'动作','name'=>'act','options'=>'act'),
			array('type'=>'string','title'=>'输入金额','name'=>'money'),
			array('type'=>'string','title'=>'备注','name'=>'remark'),
		)
	);
	$return['do']=array('1'=>'账户余额','2'=>'信用额度');
	$return['act']=array('1'=>'加','2'=>'减','3'=>'冻结','4'=>'解冻');
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='account'){
	$post=get_postdata();
	$id=intval($post['mid']);
	if(!$id){
		exi('参数错误！','error');
	}
	$item=pdo_get('jy_jdpm_member',array('mid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	if(!$post['do'] || !$post['act'] || !$post['money']){
		exi('操作项，动作和金额都需要填写','error');
	}
	$no='plg'.time().rand(10000,99999);
	if($post['do']==1){
		if($post['act']==1){
			$post['money']=intval($post['money']);
			$data['wallet_pledge']=$post['money']+$item['wallet_pledge'];
			$aliv=$data['wallet_pledge']-$item['wallet_pledge_freeze'];
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deposit','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$data['wallet_pledge'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_pledge_bill',$data2);
		}
		if($post['act']==2){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data['wallet_pledge']=$item['wallet_pledge']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deduct','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$data['wallet_pledge'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_pledge_bill',$data2);
		}
		if($post['act']==3){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data['wallet_pledge_freeze']=$item['wallet_pledge_freeze']+$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_freeze','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$item['wallet_pledge'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_pledge_bill',$data2);
		}
		if($post['act']==4){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_pledge']-$item['wallet_pledge_freeze'];
			if($item['wallet_pledge_freeze']<$post['money']){
				exi('当前可解冻余额不足'.$post['money'],'error');
			}
			$aliv=$aliv+$post['money'];
			$data['wallet_pledge_freeze']=$item['wallet_pledge_freeze']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_unfreeze','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$item['wallet_pledge'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_pledge_bill',$data2);
		}
		
	}elseif($post['do']==2){
		if($post['act']==1){
			$post['money']=intval($post['money']);
			$data['wallet_limsum']=$post['money']+$item['wallet_limsum'];
			$aliv=$data['wallet_limsum']-$item['wallet_limsum_freeze'];
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deposit','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$data['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==2){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data['wallet_limsum']=$item['wallet_limsum']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_deduct','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$data['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==3){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($aliv<$post['money']){
				exi('当前可用余额不足'.$post['money'],'error');
			}
			$aliv=$aliv-$post['money'];
			$data['wallet_limsum_freeze']=$item['wallet_limsum_freeze']+$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_freeze','createtime'=>time(),'annotation'=>$post['remark'],'expend'=>$post['money'],'balance'=>$item['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
		if($post['act']==4){
			$post['money']=intval($post['money']);
			$aliv=$item['wallet_limsum']-$item['wallet_limsum_freeze'];
			if($item['wallet_limsum_freeze']<$post['money']){
				exi('当前可解冻余额不足'.$post['money'],'error');
			}
			$aliv=$aliv+$post['money'];
			$data['wallet_limsum_freeze']=$item['wallet_limsum_freeze']-$post['money'];			
			pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			$data2=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id,'order_no'=>$no,'changetype'=>'admin_unfreeze','createtime'=>time(),'annotation'=>$post['remark'],'income'=>$post['money'],'balance'=>$item['wallet_limsum'],'usable'=>$aliv);
			pdo_insert('jy_jdpm_member_limsum_bill',$data2);
		}
	}

	exi('操作成功');
}
if($_RQ['op']=='realname'){
	$return['idcard_check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$params=array('uniacid'=>$_SESSION['uniacid']);
	if(isset($_RQ['idcard_check'])){
		$params['idcard_check']=$_RQ['idcard_check'];
		$return['params']['idcard_check']=$_RQ['idcard_check'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$fields=array('mid','truename','idcard','idcard_check','idcard_check_time');
	$list=pdo_getslice('jy_jdpm_member',$params,array($pindex,$psize),$total,$fields,'','createtime desc');
	if($list){
		foreach($list as &$item){
			$item['idcard_check_time']=$item['idcard_check_time'] ? date('Y/m/d H:i:s',$item['idcard_check_time']) :'无';
			$item['email']=$item['email']?$item['email']:'无';	
			$item['idcard_check'] = is_null($item['idcard_check'])? 0:$item['idcard_check'];
			$item['checkstatus'] = $item['idcard_check'];
			$item['idcard_check'] = $return['idcard_check'][$item['idcard_check']];
			$member=get_member($item['mid']);
			$item = array_merge($item,$member);
			$item['sex']=$item['sex']?'（男）':'（女）';
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'用户管理'),
			array('op'=>'edit','title'=>'添加用户'),
		),
		'list'=>array('key'=>'mid','data'=>'list','delall'=>false,'edit'=>false,'del_one'=>false,'list'=>array(
			array('name'=>'mid','title'=>'mid','type'=>'string'),
			array('type'=>'img_string','title'=>'登录账号','img'=>'avatar',
			'data'=>array(
				array('title'=>'账号：','name'=>'username'),
				array('title'=>'昵称：','name'=>'nickname','unit'=>'sex')
				)
			),
			array('type'=>'img_string','title'=>'姓名/身份证号',
			'data'=>array(
				array('title'=>'姓名：','name'=>'truename'),
				array('title'=>'身份证号：','name'=>'idcard')
				)
			),
			array('type'=>'img_string','title'=>'认证状态',
			'data'=>array(
				array('title'=>'认证状态：','name'=>'idcard_check'),
				array('title'=>'操作时间：','name'=>'idcard_check_time')
				)
			),
		),
		'action'=>array(
				array('op'=>'check','title'=>'实名认证','type'=>'href','plugin'=>'jy_jdpm','show'=>array('checkstatus',1)),	
			),
		),
		'search'=>array(
			array('type'=>'select','width'=>'15','title'=>'身份认证状态','name'=>'idcard_check','options'=>'idcard_check2','select_title'=>'请选择认证状态'),
		),
	
	);
	
	$return['idcard_check2']=array(
		array('id'=>0,'title'=>'未申请认证'),
		array('id'=>1,'title'=>'待认证'),
		array('id'=>2,'title'=>'已认证'),
		array('id'=>3,'title'=>'未通过'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='check'){
	$id=intval($_RQ['mid']);
	$item=pdo_get('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id),array('mid','truename','idcard','idcard_check','idcard_front','idcard_behind'));
	$item['idcard_check'] = is_null($item['idcard_check'])? 0:$item['idcard_check'];
	$member=get_member($id);
	$item = array_merge($item,$member);
	$htmls=array(
		'type'=>'edit',
		'post'=>'docheck',
		'desc'=>'实名认证',
		'edit'=>array(
			array('type'=>'string','title'=>'登录账号','name'=>'username','read'=>true),
			array('type'=>'string','title'=>'真实姓名','name'=>'truename'),
			array('type'=>'string','title'=>'身份证号','name'=>'idcard'),
			array('type'=>'image','title'=>'身份证正面照片','name'=>'idcard_front','read'=>true),
			array('type'=>'image','title'=>'身份证反面照片','name'=>'idcard_behind','read'=>true),
			array('name'=>'idcard_check','title'=>'实名认证','type'=>'radio','options'=>'check'),
			
		)
	);
	$return['check']=array('0'=>'未申请认证','1'=>'待认证','2'=>'已认证','3'=>'未通过');
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='docheck'){
	$post=get_postdata(); 
	$id=intval($post['mid']);
	if(!$id){
		exi('参数错误！','error');
	}	
	$data=array('idcard_check_time'=>TIMESTAMP,'truename'=>trim($post['truename']),'idcard'=>trim($post['idcard']),'idcard_front'=>$post['idcard_front'],'idcard_behind'=>$post['idcard_behind'],'idcard_check'=>$post['idcard_check'],);
	pdo_update('jy_jdpm_member',$data,array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
	$mobile = pdo_getcolumn('core_members',array('id'=>$id),'mobile');
	if($mobile){
		//$this->model('notice')->set_sms($mobile,'您的身份证验证成功!',4);
	}
	if($post['idcard_check'] == 3){
		$msg = '实名验证审核失败!请重新提交！';
		$this->model('notice')->set_websms($msg,0,$id,'jy_jdpm/member.safety/idcard/');
	}
	if($post['idcard_check'] == 2){
		$msg = '您的身份证验证成功!';
		$this->model('notice')->set_websms($msg,0,$id);
	}
	
	
	exi('操作成功','list');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['mid']);
	if($id){
		$mid=pdo_getcolumn('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id),'mid');	
		pdo_delete('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$mid));
		pdo_delete('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
				
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				$mid=pdo_getcolumn('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id),'mid');	
				pdo_delete('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$mid));
				pdo_delete('jy_jdpm_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$id));
			}
		}
	}
	exi('删除成功！');
}